import axios from "axios";
/**
 * @description axios初始化
 */
const instance = axios.create({
  baseURL: import.meta.env.DEV ? import.meta.env.VITE_APP_BASE_API : "",
  // baseURL: "http://192.168.100.191:801/",
  // baseURL: "http://192.168.100.5:8001/index.php/",
  // baseURL: "http://10.0.20.88:80/",
  baseURL: "https://mysecurity.yeqiyun.cn/",

  timeout: 6 * 1000,
});

/**
 * 请求拦截
 */
instance.interceptors.request.use(
  (config) => {
    if (config.method === "get") {
      const params = config.params || {};
      params.t = Date.now();
    }
    config.headers['Content-Type'] = 'application/json; charset=utf-8';
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

/**
 * 响应拦截
 */

instance.interceptors.response.use(
  (response) => {
    let { status, data } = response;
    // console.log(data,'响应数据')
    if (status === 200) {
      return data;
    } else {
      return Promise.reject(response);
    }
  },
  (error) => {
    console.log(error);
    return Promise.reject(error);
  }
);

export default instance;
